package com.thenie.seckill.config;

import com.thenie.seckill.interceptor.LoginInterceptor;
import com.thenie.seckill.vo.CurrentUserArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Configuration
public class LoginWebConfig extends WebMvcConfigurationSupport {
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 登陆拦截路径
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") //添加拦截路径
                .excludePathPatterns("/","/login/**",  //禁止拦截 / /login请求
                        "/bootstrap/**","/img/**","/jquery-validation/**","/js/**","/layer/**");//禁止拦截 静态资源请求
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }

    /**
     * Controller 配置参数解析器
     * @param argumentResolvers
     */
    @Override
    public void addArgumentResolvers(List argumentResolvers) {
        argumentResolvers.add(new CurrentUserArgumentResolver());
    }

}
